package com.vspush.manage;

import io.netty.buffer.Unpooled;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.CharsetUtil;

import java.net.InetSocketAddress;

import com.vspush.manage.type.MesssageType;
import com.vspush.udp.core.Service;
import com.vspush.util.Base164;

public abstract class MessageAbstract {
	
	
	
	private RouteManange rt = new RouteManange();
	
	public abstract  void sendMessage(String userName,String msg);
	
	public void sendMessage(String userName,String msg,MesssageType fa){
		msg = fa.getName()+Base164.encodeToString(msg);
		InetSocketAddress isa = rt.getAddressByUserName(userName);
		Service.mChannel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(msg, CharsetUtil.UTF_8),isa));
	}
	public void sendMessage(InetSocketAddress  isa,String msg,MesssageType fa){
		msg = fa.getName()+Base164.encodeToString(msg);
		Service.mChannel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(msg, CharsetUtil.UTF_8),isa));
	}

}
